home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr30 / dscrnv12.zip / DSCRNSAV.ASM next >
Assembly Source File  |  1993-05-04  |  8KB  |  250 lines

  1. ; Program dscrnsav.asm
  2. ; David Markovitch 1/12/90 and Peter Summers 21/9/91
  3.  
  4. IDEAL
  5.  
  6. SEGMENT CODE
  7. ASSUME CS: CODE, DS: CODE
  8.  
  9. org 100h
  10.  
  11. start:
  12.   jmp init          ; jump to initialization
  13.  
  14. shft_cnt    equ 37   ; ticks between screen shifts  37 = 2 sec
  15.  
  16. id          db "DSCRNSAV,DMPS"
  17. maxcount    dw 5465  ; timer ticks for delay 5465 = 5 min
  18. old9_ofs    dw ?     ; old int 9 address
  19. old9_seg    dw ?
  20. old1C_ofs   dw ?     ; old int 1C address
  21. old1C_seg   dw ?
  22. old_tail    dw ?     ; keyboard buffer tail
  23. off_flg     db 0     ; 1 = disable blanking  0 = normal operation    
  24. scr_offst   dw 0     ; offset for shifting screen
  25. blank       db 0     ; 1 = 'blank' screen  0 = normal screen
  26. turn_on     db 0     ; 1 = unblank screen  0 = nothing
  27. count       dw 0     ; tick counter for blanking
  28.  
  29. ;------------------------------------------------------------------------------
  30.  
  31. proc new9                 ; new int 9  (keyboard)
  32.   push es
  33.   push ds
  34.   push ax
  35.   push cs
  36.   pop ds
  37.   mov ax,40h
  38.   mov es,ax
  39.   mov ax,[word es: 1Ch]    ; save keyboard buffer tail pointer   
  40.   mov [old_tail],ax
  41.   pushf                    ; do bios keyboard handler
  42.   call [dword old9_ofs]
  43.   cmp [blank],0            ; check for blank screen
  44.   jne rest_scrn
  45.   mov [count],0            ; reset tick counter
  46.   jmp exit_9
  47.  
  48. rest_scrn:                 ; set flag to unblank screen
  49.   mov [turn_on],1
  50.   mov ax,[old_tail]        ; restore tail pointer to remove key from buffer
  51.   mov [word es: 1Ch],ax
  52. exit_9:
  53.   pop ax
  54.   pop ds
  55.   pop es
  56.   iret
  57. endp new9
  58.  
  59. ;------------------------------------------------------------------------------
  60.  
  61. proc new1C                 ; new int 1C  (timer tick)
  62.   sti                      ; enable interrupts
  63.   push es
  64.   push ds
  65.   push dx
  66.   push ax
  67.   push cs
  68.   pop ds
  69.   mov ax,40h
  70.   mov es,ax
  71.   cmp [turn_on],0          ; check if flag set to restore screen
  72.   je if_blank              ; jump to check for blank screen if flag not set
  73.  
  74.   mov [turn_on],0          ; restore original video buffer start
  75.   mov [blank],0
  76.   mov ax,[word es: 4Eh]    ; get bios video buffer start (bytes)
  77.   shr ax,1                 ; convert to words
  78.   push ax
  79.   jmp do_crt               ; set crt controller 
  80.  
  81. if_blank:                  
  82.   cmp [off_flg],0          ; exit if disabled
  83.   jne exit_1C
  84.   cmp [blank],0            ; check if screen already blank
  85.   jne chk_shift            ; if blank then jump to check if ready to shift 
  86.  
  87.   inc [count]              ; screen not blank - check if time to blank
  88.   mov ax,[maxcount]
  89.   cmp [count],ax
  90.   jne exit_1C              ; exit if not time to blank
  91.  
  92.   mov [blank],1            ; set blank screen flag
  93.   jmp do_shift             ; shift screen 
  94.  
  95. chk_shift:                 ; if screen blank - shift every shft_cnt ticks  
  96.   inc [count]
  97.   cmp [count],shft_cnt
  98.   jne exit_1C              ; exit if not time to shift
  99.  
  100. do_shift:                  
  101.   mov ax,[scr_offst]       ; get our video buffer offset (words)
  102.   add ax,1003              ; shift 1003 words
  103.   and ax,7FFh              ; limit to first 4K of video buffer
  104.   mov [scr_offst],ax       ; save our new video buffer offset
  105.   mov dx,[word es: 4Eh]    ; get bios video buffer start (bytes)
  106.   shr dx,1                 ; convert to words
  107.   add ax,dx                ; add our offset
  108.   push ax
  109.  
  110. do_crt:                    ; set crt controller
  111.   mov dx,[es: 63h]         ; crt controller base address
  112.   mov al,12                ; access register 12
  113.   out dx,al
  114.   inc dx
  115.   pop ax                   ; pop starting address 
  116.   xchg ah,al
  117.   out dx,al                ; write hi (start address) to register 12
  118.   dec dx
  119.   push ax                  ; push starting address
  120.   mov al,13                ; access register 13
  121.   out dx,al
  122.   inc dx
  123.   pop ax                   ; pop starting address
  124.   xchg ah,al
  125.   out dx,al                ; write lo (start address) to register 13
  126.   mov [count],0            ; reset tick counter
  127.  
  128. exit_1C:
  129.   pop ax
  130.   pop dx
  131.   pop ds
  132.   pop es
  133.   jmp [dword cs: old1C_ofs] 
  134.  
  135.  
  136.  
  137. endp new1C
  138.  
  139. ;------------------------------------------------------------------------------
  140.  
  141. init_junk:
  142.  
  143. load_msg    db 13,10,"Dscrnsav screen saver resident, v1.2"
  144.         db " by David Markovich and Peter Summers",13,10
  145.             db " SYNTAX: dscrnsav [delay], 0 disables,"
  146.             db " 1-9 re-enables, default=5",13,10,10,"$"
  147. dsabl_msg   db 13,10,"Dscrnsav disabled",13,10,"$"
  148. enabl_msg   db 13,10,"Dscrnsav enabled",13,10,"$"
  149. err1_msg    db 13,10,"Invalid command line parameter",13,10,"$"
  150. err2_msg    db 13,10,"Dscrnsav not resident",13,10,"$"
  151.  
  152. init:                      ; initialization
  153.   mov si,81h
  154.   mov dx,offset err1_msg   ; "Invalid command line parameter"
  155. parse_loop:                ; check for number on command line
  156.   lodsb
  157.   cmp al," "
  158.   je parse_loop            ; skip spaces
  159.   cmp al,13
  160.   je end_parse             ; jump if no parameter
  161.   cmp al,"9"
  162.   jg out_err               ; invalid parameter
  163.   cmp al,"0"
  164.   jl out_err               ; invalid parameter
  165.   cmp al,"0"
  166.   jne set_time
  167.   mov [off_flg],1          ; set disable flag
  168. set_time:
  169.   mov ah,0
  170.   sub al,"0"
  171.   mov bx,1093
  172.   mul bx
  173.   mov [maxcount],ax
  174. end_parse:
  175.   cld                      ; search for a previous copy
  176.   mov [word start],0       ; fingerprint
  177.   mov bx,0                 ; bx = start segment
  178.   mov ax,cs                ; ax = current segment
  179.   cmp ax,0A000h        ; Assume first load if running in high memory.
  180.   jae no_copies
  181. chk_prev:                  
  182.   inc bx                   ; increment segment
  183.   cmp ax,bx                ; check if equals current segment
  184.   jne next
  185.   mov bx,0A000h        ; if yes, move search to high memory
  186. next:
  187.   cmp bx,0FFFFh        ; end search if end of memory reached
  188.   je no_copies
  189.   mov es,bx
  190.   mov si,offset start
  191.   mov di,si
  192.   mov cx,16                ; compare first 16 bytes of each segment
  193.   repe cmpsb
  194.   jne chk_prev             ; repeat if no match
  195.  
  196.   mov ax,[maxcount]        ; copy found - set time for activation
  197.   mov [es: maxcount],ax
  198.   mov al,[off_flg]         ; change enable/disable flag
  199.   mov [es: off_flg],al
  200.   mov [es: count],0        ; reset tick count
  201.   mov dx,offset enabl_msg  ; "Dscrnsav enabled"
  202.   cmp al,0
  203.   je out_msg               ; copy enabled - errorlevel = 0
  204.  
  205.   mov dx,offset dsabl_msg  ; "Dscrnsav disabled"
  206.   mov al,0                 ; errorlevel = 0
  207.   jmp out_msg              ; copy disabled
  208.  
  209. no_copies:
  210.   mov dx,offset err2_msg   ; "Dscrnsav not resident"
  211.   cmp [off_flg],0  
  212.   je install               ; ok to install
  213.   
  214. out_err:
  215.   mov al,1
  216. out_msg:
  217.   mov ah,9                 ; display message
  218.   int 21h
  219.   mov ah,4Ch               ; terminate with errorlevel = al
  220.   int 21h
  221.  
  222. install:                   ; make program resident
  223.   mov ax,3509H             ; get old int 9 address
  224.   int 21H
  225.   mov ax,es
  226.   mov [old9_seg],ax        ; save old int 9 address  (keyboard)
  227.   mov [old9_ofs],bx
  228.   mov ax,351CH             ; get old int 1C address  (timer tick)
  229.   int 21H
  230.   mov ax,es
  231.   mov [old1C_seg],ax       ; save old int 1C address
  232.   mov [old1C_ofs],bx
  233.   mov dx,offset new9       ; set int 9 to point to our code
  234.   mov ax,2509H
  235.   int 21H
  236.   mov dx,offset new1C      ; set int 1C to point to our code
  237.   mov ax,251CH
  238.   int 21H
  239.   mov dx,offset load_msg   ; "Dscrnsav loaded"
  240.   mov ah,9
  241.   int 21h                  ; display message
  242.   mov dx,(init_junk - start + 256 + 16)/16
  243.   mov ax,3100H             ; terminate and stay resident
  244.   int 21H
  245.  
  246. ends
  247. end start
  248.  
  249. 
  250.